package com.hui.mail.config;

import com.hui.server.entity.MailConstants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @BelongsProject: yeb
 * @BelongsPackage: com.hui.server.common
 * @Author: HUI
 * @CreateTime: 2022-04-15 18:11
 * @Description: 發佈確認
 */
@Configuration
public class ConfirmConfig {

    //声明业务 Exchange
    @Bean("confirmExchange")
    public DirectExchange confirmExchange(){
        return new DirectExchange(MailConstants.MAIL_EXCHANGE_NAME);
    }
    // 声明确认队列
    @Bean("confirmQueue")
    public Queue confirmQueue(){
        return QueueBuilder.durable(MailConstants.MAIL_QUEUE_NAME).build();
    }
    // 声明确认队列绑定关系
    @Bean
    public Binding queueBinding(@Qualifier("confirmQueue") Queue queue,
                                @Qualifier("confirmExchange") DirectExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MailConstants.MAIL_ROUTING_KEY_NAME);
    }
}
